//============================================================================
// Copyright (C) 2009-2013 Brett R. Jones
//
// Issued to public domain 2013
//
// brettjones1900@gmail.com
// http://www.p2panarchy.com
//============================================================================

#include "FriendMatch.h"

//============================================================================
//! describe friend state
const char * DescribeFriendState( EFriendState eFriendState )
{
	switch( eFriendState )
	{
	case eFriendStateAnonymous:	// anonymous user
		return "Anonymous ";
	case eFriendStateGuest:		// guest user
		return "Guest ";
	case eFriendStateFriend:	// friend user
		return "Friend ";
	default:
		return "Ignore ";
	}
}

//=== constructor ===//
FriendMatch::FriendMatch() : m_u8FriendMatch(0x11){} // assume anonymous
//! return true if is ignored
bool			FriendMatch::isIgnored()											{ return eFriendStateIgnore == getMyFriendshipToHim(); }
//! return true if is Anonymous
bool			FriendMatch::isAnonymous()										{ return eFriendStateAnonymous == getMyFriendshipToHim(); }
//! return true if is Guest
bool			FriendMatch::isGuest()											{ return eFriendStateGuest == getMyFriendshipToHim(); }
//! return true if is Friend
bool			FriendMatch::isFriend()											{ return eFriendStateFriend == getMyFriendshipToHim(); }
//! set my permissions to him as ignored
void			FriendMatch::makeIgnored()										{ setMyFriendshipToHim(eFriendStateIgnore); }
//! set my permissions to him as Anonymous
void			FriendMatch::makeAnonymous()										{ setMyFriendshipToHim(eFriendStateAnonymous); }
//! set my permissions to him as Guest
void			FriendMatch::makeGuest()											{ setMyFriendshipToHim(eFriendStateGuest); }
//! set my permissions to him as Friend
void			FriendMatch::makeFriend()										{ setMyFriendshipToHim(eFriendStateFriend); }
//! wants to be friend
bool			FriendMatch::wantsToBeFriend()									{ return eFriendStateFriend == getHisFriendshipToMe(); }


//! set permission level I have given to friend
void			FriendMatch::setMyFriendshipToHim( EFriendState eFriendState )	
{ 
	m_u8FriendMatch &= 0xf0; 
	m_u8FriendMatch |= eFriendState; 
}
//! get permission level I have given to friend
EFriendState	FriendMatch::getMyFriendshipToHim( void )						{ return (EFriendState)(m_u8FriendMatch & 0x0f); }

//! set permission level he has given to me
void			FriendMatch::setHisFriendshipToMe( EFriendState eFriendState )	
{ 
	m_u8FriendMatch &= 0x0f; 
	m_u8FriendMatch |= (eFriendState << 4); 
}

//! get permission level he has given to me
EFriendState	FriendMatch::getHisFriendshipToMe( void )						{ return (EFriendState)((m_u8FriendMatch >> 4) & 0x0f); }

//! reverse the permissions
void			FriendMatch::reversePermissions( void )
{
	U8 u8TmpPermission = m_u8FriendMatch << 4;
	m_u8FriendMatch = u8TmpPermission | (( m_u8FriendMatch >> 4 ) & 0x0f);
}
//! return string with friend state He has given Me
void			FriendMatch::describeHisFriendshipToMe( std::string & strRetPermission ) { strRetPermission = DescribeFriendState( getHisFriendshipToMe() ); }
//! return string with friend state He has given Me
const char *	FriendMatch::describeHisFriendshipToMe( void )							{ return DescribeFriendState( getHisFriendshipToMe() ); }
//! return string with friend state I have given Him
void			FriendMatch::describeMyFriendshipToHim( std::string & strRetPermission ) { strRetPermission = DescribeFriendState( getMyFriendshipToHim() ); }
//! return string with friend state I have given Him
const char *	FriendMatch::describeMyFriendshipToHim( void )							{ return DescribeFriendState( getMyFriendshipToHim() ); }

//////////////////////////